{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# type(np.NaN)  # NaN是float类型\n",
    "# type(np.nan)  # np.nan <==> np.NaN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>Description</th>\n",
       "      <th>Director</th>\n",
       "      <th>Actors</th>\n",
       "      <th>Year</th>\n",
       "      <th>Runtime (Minutes)</th>\n",
       "      <th>Rating</th>\n",
       "      <th>Votes</th>\n",
       "      <th>Revenue (Millions)</th>\n",
       "      <th>Metascore</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Guardians of the Galaxy</td>\n",
       "      <td>Action,Adventure,Sci-Fi</td>\n",
       "      <td>A group of intergalactic criminals are forced ...</td>\n",
       "      <td>James Gunn</td>\n",
       "      <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n",
       "      <td>2014</td>\n",
       "      <td>121</td>\n",
       "      <td>8.1</td>\n",
       "      <td>757074</td>\n",
       "      <td>333.13</td>\n",
       "      <td>76.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Prometheus</td>\n",
       "      <td>Adventure,Mystery,Sci-Fi</td>\n",
       "      <td>Following clues to the origin of mankind, a te...</td>\n",
       "      <td>Ridley Scott</td>\n",
       "      <td>Noomi Rapace, Logan Marshall-Green, Michael Fa...</td>\n",
       "      <td>2012</td>\n",
       "      <td>124</td>\n",
       "      <td>7.0</td>\n",
       "      <td>485820</td>\n",
       "      <td>126.46</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Split</td>\n",
       "      <td>Horror,Thriller</td>\n",
       "      <td>Three girls are kidnapped by a man with a diag...</td>\n",
       "      <td>M. Night Shyamalan</td>\n",
       "      <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n",
       "      <td>2016</td>\n",
       "      <td>117</td>\n",
       "      <td>7.3</td>\n",
       "      <td>157606</td>\n",
       "      <td>138.12</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Sing</td>\n",
       "      <td>Animation,Comedy,Family</td>\n",
       "      <td>In a city of humanoid animals, a hustling thea...</td>\n",
       "      <td>Christophe Lourdelet</td>\n",
       "      <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n",
       "      <td>2016</td>\n",
       "      <td>108</td>\n",
       "      <td>7.2</td>\n",
       "      <td>60545</td>\n",
       "      <td>270.32</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Suicide Squad</td>\n",
       "      <td>Action,Adventure,Fantasy</td>\n",
       "      <td>A secret government agency recruits some of th...</td>\n",
       "      <td>David Ayer</td>\n",
       "      <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n",
       "      <td>2016</td>\n",
       "      <td>123</td>\n",
       "      <td>6.2</td>\n",
       "      <td>393727</td>\n",
       "      <td>325.02</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>The Great Wall</td>\n",
       "      <td>Action,Adventure,Fantasy</td>\n",
       "      <td>European mercenaries searching for black powde...</td>\n",
       "      <td>Yimou Zhang</td>\n",
       "      <td>Matt Damon, Tian Jing, Willem Dafoe, Andy Lau</td>\n",
       "      <td>2016</td>\n",
       "      <td>103</td>\n",
       "      <td>6.1</td>\n",
       "      <td>56036</td>\n",
       "      <td>45.13</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>La La Land</td>\n",
       "      <td>Comedy,Drama,Music</td>\n",
       "      <td>A jazz pianist falls for an aspiring actress i...</td>\n",
       "      <td>Damien Chazelle</td>\n",
       "      <td>Ryan Gosling, Emma Stone, Rosemarie DeWitt, J....</td>\n",
       "      <td>2016</td>\n",
       "      <td>128</td>\n",
       "      <td>8.3</td>\n",
       "      <td>258682</td>\n",
       "      <td>151.06</td>\n",
       "      <td>93.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>Mindhorn</td>\n",
       "      <td>Comedy</td>\n",
       "      <td>A has-been actor best known for playing the ti...</td>\n",
       "      <td>Sean Foley</td>\n",
       "      <td>Essie Davis, Andrea Riseborough, Julian Barrat...</td>\n",
       "      <td>2016</td>\n",
       "      <td>89</td>\n",
       "      <td>6.4</td>\n",
       "      <td>2490</td>\n",
       "      <td>NaN</td>\n",
       "      <td>71.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>The Lost City of Z</td>\n",
       "      <td>Action,Adventure,Biography</td>\n",
       "      <td>A true-life drama, centering on British explor...</td>\n",
       "      <td>James Gray</td>\n",
       "      <td>Charlie Hunnam, Robert Pattinson, Sienna Mille...</td>\n",
       "      <td>2016</td>\n",
       "      <td>141</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7188</td>\n",
       "      <td>8.01</td>\n",
       "      <td>78.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>Passengers</td>\n",
       "      <td>Adventure,Drama,Romance</td>\n",
       "      <td>A spacecraft traveling to a distant colony pla...</td>\n",
       "      <td>Morten Tyldum</td>\n",
       "      <td>Jennifer Lawrence, Chris Pratt, Michael Sheen,...</td>\n",
       "      <td>2016</td>\n",
       "      <td>116</td>\n",
       "      <td>7.0</td>\n",
       "      <td>192177</td>\n",
       "      <td>100.01</td>\n",
       "      <td>41.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Rank                    Title                       Genre  \\\n",
       "0     1  Guardians of the Galaxy     Action,Adventure,Sci-Fi   \n",
       "1     2               Prometheus    Adventure,Mystery,Sci-Fi   \n",
       "2     3                    Split             Horror,Thriller   \n",
       "3     4                     Sing     Animation,Comedy,Family   \n",
       "4     5            Suicide Squad    Action,Adventure,Fantasy   \n",
       "5     6           The Great Wall    Action,Adventure,Fantasy   \n",
       "6     7               La La Land          Comedy,Drama,Music   \n",
       "7     8                 Mindhorn                      Comedy   \n",
       "8     9       The Lost City of Z  Action,Adventure,Biography   \n",
       "9    10               Passengers     Adventure,Drama,Romance   \n",
       "\n",
       "                                         Description              Director  \\\n",
       "0  A group of intergalactic criminals are forced ...            James Gunn   \n",
       "1  Following clues to the origin of mankind, a te...          Ridley Scott   \n",
       "2  Three girls are kidnapped by a man with a diag...    M. Night Shyamalan   \n",
       "3  In a city of humanoid animals, a hustling thea...  Christophe Lourdelet   \n",
       "4  A secret government agency recruits some of th...            David Ayer   \n",
       "5  European mercenaries searching for black powde...           Yimou Zhang   \n",
       "6  A jazz pianist falls for an aspiring actress i...       Damien Chazelle   \n",
       "7  A has-been actor best known for playing the ti...            Sean Foley   \n",
       "8  A true-life drama, centering on British explor...            James Gray   \n",
       "9  A spacecraft traveling to a distant colony pla...         Morten Tyldum   \n",
       "\n",
       "                                              Actors  Year  Runtime (Minutes)  \\\n",
       "0  Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...  2014                121   \n",
       "1  Noomi Rapace, Logan Marshall-Green, Michael Fa...  2012                124   \n",
       "2  James McAvoy, Anya Taylor-Joy, Haley Lu Richar...  2016                117   \n",
       "3  Matthew McConaughey,Reese Witherspoon, Seth Ma...  2016                108   \n",
       "4  Will Smith, Jared Leto, Margot Robbie, Viola D...  2016                123   \n",
       "5      Matt Damon, Tian Jing, Willem Dafoe, Andy Lau  2016                103   \n",
       "6  Ryan Gosling, Emma Stone, Rosemarie DeWitt, J....  2016                128   \n",
       "7  Essie Davis, Andrea Riseborough, Julian Barrat...  2016                 89   \n",
       "8  Charlie Hunnam, Robert Pattinson, Sienna Mille...  2016                141   \n",
       "9  Jennifer Lawrence, Chris Pratt, Michael Sheen,...  2016                116   \n",
       "\n",
       "   Rating   Votes  Revenue (Millions)  Metascore  \n",
       "0     8.1  757074              333.13       76.0  \n",
       "1     7.0  485820              126.46       65.0  \n",
       "2     7.3  157606              138.12       62.0  \n",
       "3     7.2   60545              270.32       59.0  \n",
       "4     6.2  393727              325.02       40.0  \n",
       "5     6.1   56036               45.13       42.0  \n",
       "6     8.3  258682              151.06       93.0  \n",
       "7     6.4    2490                 NaN       71.0  \n",
       "8     7.1    7188                8.01       78.0  \n",
       "9     7.0  192177              100.01       41.0  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie = pd.read_csv('./data/IMDB-Movie-Data.csv')\n",
    "movie.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 缺失值的判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.any(pd.isnull(movie))  # 如果movie中存在NaN值就返回True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.all(pd.notnull(movie))  # 如果movie中所有元素都不是NaN返回True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 缺失值的删除和替换"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 缺失值的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>Description</th>\n",
       "      <th>Director</th>\n",
       "      <th>Actors</th>\n",
       "      <th>Year</th>\n",
       "      <th>Runtime (Minutes)</th>\n",
       "      <th>Rating</th>\n",
       "      <th>Votes</th>\n",
       "      <th>Revenue (Millions)</th>\n",
       "      <th>Metascore</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Guardians of the Galaxy</td>\n",
       "      <td>Action,Adventure,Sci-Fi</td>\n",
       "      <td>A group of intergalactic criminals are forced ...</td>\n",
       "      <td>James Gunn</td>\n",
       "      <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n",
       "      <td>2014</td>\n",
       "      <td>121</td>\n",
       "      <td>8.1</td>\n",
       "      <td>757074</td>\n",
       "      <td>333.13</td>\n",
       "      <td>76.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Prometheus</td>\n",
       "      <td>Adventure,Mystery,Sci-Fi</td>\n",
       "      <td>Following clues to the origin of mankind, a te...</td>\n",
       "      <td>Ridley Scott</td>\n",
       "      <td>Noomi Rapace, Logan Marshall-Green, Michael Fa...</td>\n",
       "      <td>2012</td>\n",
       "      <td>124</td>\n",
       "      <td>7.0</td>\n",
       "      <td>485820</td>\n",
       "      <td>126.46</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Split</td>\n",
       "      <td>Horror,Thriller</td>\n",
       "      <td>Three girls are kidnapped by a man with a diag...</td>\n",
       "      <td>M. Night Shyamalan</td>\n",
       "      <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n",
       "      <td>2016</td>\n",
       "      <td>117</td>\n",
       "      <td>7.3</td>\n",
       "      <td>157606</td>\n",
       "      <td>138.12</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Sing</td>\n",
       "      <td>Animation,Comedy,Family</td>\n",
       "      <td>In a city of humanoid animals, a hustling thea...</td>\n",
       "      <td>Christophe Lourdelet</td>\n",
       "      <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n",
       "      <td>2016</td>\n",
       "      <td>108</td>\n",
       "      <td>7.2</td>\n",
       "      <td>60545</td>\n",
       "      <td>270.32</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Suicide Squad</td>\n",
       "      <td>Action,Adventure,Fantasy</td>\n",
       "      <td>A secret government agency recruits some of th...</td>\n",
       "      <td>David Ayer</td>\n",
       "      <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n",
       "      <td>2016</td>\n",
       "      <td>123</td>\n",
       "      <td>6.2</td>\n",
       "      <td>393727</td>\n",
       "      <td>325.02</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>The Great Wall</td>\n",
       "      <td>Action,Adventure,Fantasy</td>\n",
       "      <td>European mercenaries searching for black powde...</td>\n",
       "      <td>Yimou Zhang</td>\n",
       "      <td>Matt Damon, Tian Jing, Willem Dafoe, Andy Lau</td>\n",
       "      <td>2016</td>\n",
       "      <td>103</td>\n",
       "      <td>6.1</td>\n",
       "      <td>56036</td>\n",
       "      <td>45.13</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>La La Land</td>\n",
       "      <td>Comedy,Drama,Music</td>\n",
       "      <td>A jazz pianist falls for an aspiring actress i...</td>\n",
       "      <td>Damien Chazelle</td>\n",
       "      <td>Ryan Gosling, Emma Stone, Rosemarie DeWitt, J....</td>\n",
       "      <td>2016</td>\n",
       "      <td>128</td>\n",
       "      <td>8.3</td>\n",
       "      <td>258682</td>\n",
       "      <td>151.06</td>\n",
       "      <td>93.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>The Lost City of Z</td>\n",
       "      <td>Action,Adventure,Biography</td>\n",
       "      <td>A true-life drama, centering on British explor...</td>\n",
       "      <td>James Gray</td>\n",
       "      <td>Charlie Hunnam, Robert Pattinson, Sienna Mille...</td>\n",
       "      <td>2016</td>\n",
       "      <td>141</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7188</td>\n",
       "      <td>8.01</td>\n",
       "      <td>78.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>Passengers</td>\n",
       "      <td>Adventure,Drama,Romance</td>\n",
       "      <td>A spacecraft traveling to a distant colony pla...</td>\n",
       "      <td>Morten Tyldum</td>\n",
       "      <td>Jennifer Lawrence, Chris Pratt, Michael Sheen,...</td>\n",
       "      <td>2016</td>\n",
       "      <td>116</td>\n",
       "      <td>7.0</td>\n",
       "      <td>192177</td>\n",
       "      <td>100.01</td>\n",
       "      <td>41.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>Fantastic Beasts and Where to Find Them</td>\n",
       "      <td>Adventure,Family,Fantasy</td>\n",
       "      <td>The adventures of writer Newt Scamander in New...</td>\n",
       "      <td>David Yates</td>\n",
       "      <td>Eddie Redmayne, Katherine Waterston, Alison Su...</td>\n",
       "      <td>2016</td>\n",
       "      <td>133</td>\n",
       "      <td>7.5</td>\n",
       "      <td>232072</td>\n",
       "      <td>234.02</td>\n",
       "      <td>66.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Rank                                    Title                       Genre  \\\n",
       "0      1                  Guardians of the Galaxy     Action,Adventure,Sci-Fi   \n",
       "1      2                               Prometheus    Adventure,Mystery,Sci-Fi   \n",
       "2      3                                    Split             Horror,Thriller   \n",
       "3      4                                     Sing     Animation,Comedy,Family   \n",
       "4      5                            Suicide Squad    Action,Adventure,Fantasy   \n",
       "5      6                           The Great Wall    Action,Adventure,Fantasy   \n",
       "6      7                               La La Land          Comedy,Drama,Music   \n",
       "8      9                       The Lost City of Z  Action,Adventure,Biography   \n",
       "9     10                               Passengers     Adventure,Drama,Romance   \n",
       "10    11  Fantastic Beasts and Where to Find Them    Adventure,Family,Fantasy   \n",
       "\n",
       "                                          Description              Director  \\\n",
       "0   A group of intergalactic criminals are forced ...            James Gunn   \n",
       "1   Following clues to the origin of mankind, a te...          Ridley Scott   \n",
       "2   Three girls are kidnapped by a man with a diag...    M. Night Shyamalan   \n",
       "3   In a city of humanoid animals, a hustling thea...  Christophe Lourdelet   \n",
       "4   A secret government agency recruits some of th...            David Ayer   \n",
       "5   European mercenaries searching for black powde...           Yimou Zhang   \n",
       "6   A jazz pianist falls for an aspiring actress i...       Damien Chazelle   \n",
       "8   A true-life drama, centering on British explor...            James Gray   \n",
       "9   A spacecraft traveling to a distant colony pla...         Morten Tyldum   \n",
       "10  The adventures of writer Newt Scamander in New...           David Yates   \n",
       "\n",
       "                                               Actors  Year  \\\n",
       "0   Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...  2014   \n",
       "1   Noomi Rapace, Logan Marshall-Green, Michael Fa...  2012   \n",
       "2   James McAvoy, Anya Taylor-Joy, Haley Lu Richar...  2016   \n",
       "3   Matthew McConaughey,Reese Witherspoon, Seth Ma...  2016   \n",
       "4   Will Smith, Jared Leto, Margot Robbie, Viola D...  2016   \n",
       "5       Matt Damon, Tian Jing, Willem Dafoe, Andy Lau  2016   \n",
       "6   Ryan Gosling, Emma Stone, Rosemarie DeWitt, J....  2016   \n",
       "8   Charlie Hunnam, Robert Pattinson, Sienna Mille...  2016   \n",
       "9   Jennifer Lawrence, Chris Pratt, Michael Sheen,...  2016   \n",
       "10  Eddie Redmayne, Katherine Waterston, Alison Su...  2016   \n",
       "\n",
       "    Runtime (Minutes)  Rating   Votes  Revenue (Millions)  Metascore  \n",
       "0                 121     8.1  757074              333.13       76.0  \n",
       "1                 124     7.0  485820              126.46       65.0  \n",
       "2                 117     7.3  157606              138.12       62.0  \n",
       "3                 108     7.2   60545              270.32       59.0  \n",
       "4                 123     6.2  393727              325.02       40.0  \n",
       "5                 103     6.1   56036               45.13       42.0  \n",
       "6                 128     8.3  258682              151.06       93.0  \n",
       "8                 141     7.1    7188                8.01       78.0  \n",
       "9                 116     7.0  192177              100.01       41.0  \n",
       "10                133     7.5  232072              234.02       66.0  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe.dropna(),删除的是NaN值所在的行，返回的是一个对象\n",
    "movie.dropna().head(10)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 缺失值的替换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>Description</th>\n",
       "      <th>Director</th>\n",
       "      <th>Actors</th>\n",
       "      <th>Year</th>\n",
       "      <th>Runtime (Minutes)</th>\n",
       "      <th>Rating</th>\n",
       "      <th>Votes</th>\n",
       "      <th>Revenue (Millions)</th>\n",
       "      <th>Metascore</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Guardians of the Galaxy</td>\n",
       "      <td>Action,Adventure,Sci-Fi</td>\n",
       "      <td>A group of intergalactic criminals are forced ...</td>\n",
       "      <td>James Gunn</td>\n",
       "      <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n",
       "      <td>2014</td>\n",
       "      <td>121</td>\n",
       "      <td>8.1</td>\n",
       "      <td>757074</td>\n",
       "      <td>333.13</td>\n",
       "      <td>76.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Prometheus</td>\n",
       "      <td>Adventure,Mystery,Sci-Fi</td>\n",
       "      <td>Following clues to the origin of mankind, a te...</td>\n",
       "      <td>Ridley Scott</td>\n",
       "      <td>Noomi Rapace, Logan Marshall-Green, Michael Fa...</td>\n",
       "      <td>2012</td>\n",
       "      <td>124</td>\n",
       "      <td>7.0</td>\n",
       "      <td>485820</td>\n",
       "      <td>126.46</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Split</td>\n",
       "      <td>Horror,Thriller</td>\n",
       "      <td>Three girls are kidnapped by a man with a diag...</td>\n",
       "      <td>M. Night Shyamalan</td>\n",
       "      <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n",
       "      <td>2016</td>\n",
       "      <td>117</td>\n",
       "      <td>7.3</td>\n",
       "      <td>157606</td>\n",
       "      <td>138.12</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Sing</td>\n",
       "      <td>Animation,Comedy,Family</td>\n",
       "      <td>In a city of humanoid animals, a hustling thea...</td>\n",
       "      <td>Christophe Lourdelet</td>\n",
       "      <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n",
       "      <td>2016</td>\n",
       "      <td>108</td>\n",
       "      <td>7.2</td>\n",
       "      <td>60545</td>\n",
       "      <td>270.32</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Suicide Squad</td>\n",
       "      <td>Action,Adventure,Fantasy</td>\n",
       "      <td>A secret government agency recruits some of th...</td>\n",
       "      <td>David Ayer</td>\n",
       "      <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n",
       "      <td>2016</td>\n",
       "      <td>123</td>\n",
       "      <td>6.2</td>\n",
       "      <td>393727</td>\n",
       "      <td>325.02</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>996</td>\n",
       "      <td>Secret in Their Eyes</td>\n",
       "      <td>Crime,Drama,Mystery</td>\n",
       "      <td>A tight-knit team of rising investigators, alo...</td>\n",
       "      <td>Billy Ray</td>\n",
       "      <td>Chiwetel Ejiofor, Nicole Kidman, Julia Roberts...</td>\n",
       "      <td>2015</td>\n",
       "      <td>111</td>\n",
       "      <td>6.2</td>\n",
       "      <td>27585</td>\n",
       "      <td>666.00</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>997</td>\n",
       "      <td>Hostel: Part II</td>\n",
       "      <td>Horror</td>\n",
       "      <td>Three American college students studying abroa...</td>\n",
       "      <td>Eli Roth</td>\n",
       "      <td>Lauren German, Heather Matarazzo, Bijou Philli...</td>\n",
       "      <td>2007</td>\n",
       "      <td>94</td>\n",
       "      <td>5.5</td>\n",
       "      <td>73152</td>\n",
       "      <td>17.54</td>\n",
       "      <td>46.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>998</td>\n",
       "      <td>Step Up 2: The Streets</td>\n",
       "      <td>Drama,Music,Romance</td>\n",
       "      <td>Romantic sparks occur between two dance studen...</td>\n",
       "      <td>Jon M. Chu</td>\n",
       "      <td>Robert Hoffman, Briana Evigan, Cassie Ventura,...</td>\n",
       "      <td>2008</td>\n",
       "      <td>98</td>\n",
       "      <td>6.2</td>\n",
       "      <td>70699</td>\n",
       "      <td>58.01</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>999</td>\n",
       "      <td>Search Party</td>\n",
       "      <td>Adventure,Comedy</td>\n",
       "      <td>A pair of friends embark on a mission to reuni...</td>\n",
       "      <td>Scot Armstrong</td>\n",
       "      <td>Adam Pally, T.J. Miller, Thomas Middleditch,Sh...</td>\n",
       "      <td>2014</td>\n",
       "      <td>93</td>\n",
       "      <td>5.6</td>\n",
       "      <td>4881</td>\n",
       "      <td>666.00</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1000</td>\n",
       "      <td>Nine Lives</td>\n",
       "      <td>Comedy,Family,Fantasy</td>\n",
       "      <td>A stuffy businessman finds himself trapped ins...</td>\n",
       "      <td>Barry Sonnenfeld</td>\n",
       "      <td>Kevin Spacey, Jennifer Garner, Robbie Amell,Ch...</td>\n",
       "      <td>2016</td>\n",
       "      <td>87</td>\n",
       "      <td>5.3</td>\n",
       "      <td>12435</td>\n",
       "      <td>19.64</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Rank                    Title                     Genre  \\\n",
       "0       1  Guardians of the Galaxy   Action,Adventure,Sci-Fi   \n",
       "1       2               Prometheus  Adventure,Mystery,Sci-Fi   \n",
       "2       3                    Split           Horror,Thriller   \n",
       "3       4                     Sing   Animation,Comedy,Family   \n",
       "4       5            Suicide Squad  Action,Adventure,Fantasy   \n",
       "..    ...                      ...                       ...   \n",
       "995   996     Secret in Their Eyes       Crime,Drama,Mystery   \n",
       "996   997          Hostel: Part II                    Horror   \n",
       "997   998   Step Up 2: The Streets       Drama,Music,Romance   \n",
       "998   999             Search Party          Adventure,Comedy   \n",
       "999  1000               Nine Lives     Comedy,Family,Fantasy   \n",
       "\n",
       "                                           Description              Director  \\\n",
       "0    A group of intergalactic criminals are forced ...            James Gunn   \n",
       "1    Following clues to the origin of mankind, a te...          Ridley Scott   \n",
       "2    Three girls are kidnapped by a man with a diag...    M. Night Shyamalan   \n",
       "3    In a city of humanoid animals, a hustling thea...  Christophe Lourdelet   \n",
       "4    A secret government agency recruits some of th...            David Ayer   \n",
       "..                                                 ...                   ...   \n",
       "995  A tight-knit team of rising investigators, alo...             Billy Ray   \n",
       "996  Three American college students studying abroa...              Eli Roth   \n",
       "997  Romantic sparks occur between two dance studen...            Jon M. Chu   \n",
       "998  A pair of friends embark on a mission to reuni...        Scot Armstrong   \n",
       "999  A stuffy businessman finds himself trapped ins...      Barry Sonnenfeld   \n",
       "\n",
       "                                                Actors  Year  \\\n",
       "0    Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...  2014   \n",
       "1    Noomi Rapace, Logan Marshall-Green, Michael Fa...  2012   \n",
       "2    James McAvoy, Anya Taylor-Joy, Haley Lu Richar...  2016   \n",
       "3    Matthew McConaughey,Reese Witherspoon, Seth Ma...  2016   \n",
       "4    Will Smith, Jared Leto, Margot Robbie, Viola D...  2016   \n",
       "..                                                 ...   ...   \n",
       "995  Chiwetel Ejiofor, Nicole Kidman, Julia Roberts...  2015   \n",
       "996  Lauren German, Heather Matarazzo, Bijou Philli...  2007   \n",
       "997  Robert Hoffman, Briana Evigan, Cassie Ventura,...  2008   \n",
       "998  Adam Pally, T.J. Miller, Thomas Middleditch,Sh...  2014   \n",
       "999  Kevin Spacey, Jennifer Garner, Robbie Amell,Ch...  2016   \n",
       "\n",
       "     Runtime (Minutes)  Rating   Votes  Revenue (Millions)  Metascore  \n",
       "0                  121     8.1  757074              333.13       76.0  \n",
       "1                  124     7.0  485820              126.46       65.0  \n",
       "2                  117     7.3  157606              138.12       62.0  \n",
       "3                  108     7.2   60545              270.32       59.0  \n",
       "4                  123     6.2  393727              325.02       40.0  \n",
       "..                 ...     ...     ...                 ...        ...  \n",
       "995                111     6.2   27585              666.00       45.0  \n",
       "996                 94     5.5   73152               17.54       46.0  \n",
       "997                 98     6.2   70699               58.01       50.0  \n",
       "998                 93     5.6    4881              666.00       22.0  \n",
       "999                 87     5.3   12435               19.64       11.0  \n",
       "\n",
       "[1000 rows x 12 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# fillna(替换值, inplace)  # inplace如果指定为True则更改原来的datafram对象，如果为False，则返回\n",
    "# 的是一个对象，默认是False\n",
    "# 方法一\n",
    "movie.fillna(666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Revenue (Millions)\n",
      "Metascore\n"
     ]
    }
   ],
   "source": [
    "# 方法二\n",
    "new_movie = movie\n",
    "for i in new_movie.columns:\n",
    "    if np.any(pd.isnull(new_movie[i])) == True:\n",
    "        print(i)\n",
    "        new_movie[i].fillna(666, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>Description</th>\n",
       "      <th>Director</th>\n",
       "      <th>Actors</th>\n",
       "      <th>Year</th>\n",
       "      <th>Runtime (Minutes)</th>\n",
       "      <th>Rating</th>\n",
       "      <th>Votes</th>\n",
       "      <th>Revenue (Millions)</th>\n",
       "      <th>Metascore</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Guardians of the Galaxy</td>\n",
       "      <td>Action,Adventure,Sci-Fi</td>\n",
       "      <td>A group of intergalactic criminals are forced ...</td>\n",
       "      <td>James Gunn</td>\n",
       "      <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n",
       "      <td>2014</td>\n",
       "      <td>121</td>\n",
       "      <td>8.1</td>\n",
       "      <td>757074</td>\n",
       "      <td>333.13</td>\n",
       "      <td>76.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Prometheus</td>\n",
       "      <td>Adventure,Mystery,Sci-Fi</td>\n",
       "      <td>Following clues to the origin of mankind, a te...</td>\n",
       "      <td>Ridley Scott</td>\n",
       "      <td>Noomi Rapace, Logan Marshall-Green, Michael Fa...</td>\n",
       "      <td>2012</td>\n",
       "      <td>124</td>\n",
       "      <td>7.0</td>\n",
       "      <td>485820</td>\n",
       "      <td>126.46</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Split</td>\n",
       "      <td>Horror,Thriller</td>\n",
       "      <td>Three girls are kidnapped by a man with a diag...</td>\n",
       "      <td>M. Night Shyamalan</td>\n",
       "      <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n",
       "      <td>2016</td>\n",
       "      <td>117</td>\n",
       "      <td>7.3</td>\n",
       "      <td>157606</td>\n",
       "      <td>138.12</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Sing</td>\n",
       "      <td>Animation,Comedy,Family</td>\n",
       "      <td>In a city of humanoid animals, a hustling thea...</td>\n",
       "      <td>Christophe Lourdelet</td>\n",
       "      <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n",
       "      <td>2016</td>\n",
       "      <td>108</td>\n",
       "      <td>7.2</td>\n",
       "      <td>60545</td>\n",
       "      <td>270.32</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Suicide Squad</td>\n",
       "      <td>Action,Adventure,Fantasy</td>\n",
       "      <td>A secret government agency recruits some of th...</td>\n",
       "      <td>David Ayer</td>\n",
       "      <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n",
       "      <td>2016</td>\n",
       "      <td>123</td>\n",
       "      <td>6.2</td>\n",
       "      <td>393727</td>\n",
       "      <td>325.02</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>996</td>\n",
       "      <td>Secret in Their Eyes</td>\n",
       "      <td>Crime,Drama,Mystery</td>\n",
       "      <td>A tight-knit team of rising investigators, alo...</td>\n",
       "      <td>Billy Ray</td>\n",
       "      <td>Chiwetel Ejiofor, Nicole Kidman, Julia Roberts...</td>\n",
       "      <td>2015</td>\n",
       "      <td>111</td>\n",
       "      <td>6.2</td>\n",
       "      <td>27585</td>\n",
       "      <td>666.00</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>997</td>\n",
       "      <td>Hostel: Part II</td>\n",
       "      <td>Horror</td>\n",
       "      <td>Three American college students studying abroa...</td>\n",
       "      <td>Eli Roth</td>\n",
       "      <td>Lauren German, Heather Matarazzo, Bijou Philli...</td>\n",
       "      <td>2007</td>\n",
       "      <td>94</td>\n",
       "      <td>5.5</td>\n",
       "      <td>73152</td>\n",
       "      <td>17.54</td>\n",
       "      <td>46.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>998</td>\n",
       "      <td>Step Up 2: The Streets</td>\n",
       "      <td>Drama,Music,Romance</td>\n",
       "      <td>Romantic sparks occur between two dance studen...</td>\n",
       "      <td>Jon M. Chu</td>\n",
       "      <td>Robert Hoffman, Briana Evigan, Cassie Ventura,...</td>\n",
       "      <td>2008</td>\n",
       "      <td>98</td>\n",
       "      <td>6.2</td>\n",
       "      <td>70699</td>\n",
       "      <td>58.01</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>999</td>\n",
       "      <td>Search Party</td>\n",
       "      <td>Adventure,Comedy</td>\n",
       "      <td>A pair of friends embark on a mission to reuni...</td>\n",
       "      <td>Scot Armstrong</td>\n",
       "      <td>Adam Pally, T.J. Miller, Thomas Middleditch,Sh...</td>\n",
       "      <td>2014</td>\n",
       "      <td>93</td>\n",
       "      <td>5.6</td>\n",
       "      <td>4881</td>\n",
       "      <td>666.00</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1000</td>\n",
       "      <td>Nine Lives</td>\n",
       "      <td>Comedy,Family,Fantasy</td>\n",
       "      <td>A stuffy businessman finds himself trapped ins...</td>\n",
       "      <td>Barry Sonnenfeld</td>\n",
       "      <td>Kevin Spacey, Jennifer Garner, Robbie Amell,Ch...</td>\n",
       "      <td>2016</td>\n",
       "      <td>87</td>\n",
       "      <td>5.3</td>\n",
       "      <td>12435</td>\n",
       "      <td>19.64</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Rank                    Title                     Genre  \\\n",
       "0       1  Guardians of the Galaxy   Action,Adventure,Sci-Fi   \n",
       "1       2               Prometheus  Adventure,Mystery,Sci-Fi   \n",
       "2       3                    Split           Horror,Thriller   \n",
       "3       4                     Sing   Animation,Comedy,Family   \n",
       "4       5            Suicide Squad  Action,Adventure,Fantasy   \n",
       "..    ...                      ...                       ...   \n",
       "995   996     Secret in Their Eyes       Crime,Drama,Mystery   \n",
       "996   997          Hostel: Part II                    Horror   \n",
       "997   998   Step Up 2: The Streets       Drama,Music,Romance   \n",
       "998   999             Search Party          Adventure,Comedy   \n",
       "999  1000               Nine Lives     Comedy,Family,Fantasy   \n",
       "\n",
       "                                           Description              Director  \\\n",
       "0    A group of intergalactic criminals are forced ...            James Gunn   \n",
       "1    Following clues to the origin of mankind, a te...          Ridley Scott   \n",
       "2    Three girls are kidnapped by a man with a diag...    M. Night Shyamalan   \n",
       "3    In a city of humanoid animals, a hustling thea...  Christophe Lourdelet   \n",
       "4    A secret government agency recruits some of th...            David Ayer   \n",
       "..                                                 ...                   ...   \n",
       "995  A tight-knit team of rising investigators, alo...             Billy Ray   \n",
       "996  Three American college students studying abroa...              Eli Roth   \n",
       "997  Romantic sparks occur between two dance studen...            Jon M. Chu   \n",
       "998  A pair of friends embark on a mission to reuni...        Scot Armstrong   \n",
       "999  A stuffy businessman finds himself trapped ins...      Barry Sonnenfeld   \n",
       "\n",
       "                                                Actors  Year  \\\n",
       "0    Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...  2014   \n",
       "1    Noomi Rapace, Logan Marshall-Green, Michael Fa...  2012   \n",
       "2    James McAvoy, Anya Taylor-Joy, Haley Lu Richar...  2016   \n",
       "3    Matthew McConaughey,Reese Witherspoon, Seth Ma...  2016   \n",
       "4    Will Smith, Jared Leto, Margot Robbie, Viola D...  2016   \n",
       "..                                                 ...   ...   \n",
       "995  Chiwetel Ejiofor, Nicole Kidman, Julia Roberts...  2015   \n",
       "996  Lauren German, Heather Matarazzo, Bijou Philli...  2007   \n",
       "997  Robert Hoffman, Briana Evigan, Cassie Ventura,...  2008   \n",
       "998  Adam Pally, T.J. Miller, Thomas Middleditch,Sh...  2014   \n",
       "999  Kevin Spacey, Jennifer Garner, Robbie Amell,Ch...  2016   \n",
       "\n",
       "     Runtime (Minutes)  Rating   Votes  Revenue (Millions)  Metascore  \n",
       "0                  121     8.1  757074              333.13       76.0  \n",
       "1                  124     7.0  485820              126.46       65.0  \n",
       "2                  117     7.3  157606              138.12       62.0  \n",
       "3                  108     7.2   60545              270.32       59.0  \n",
       "4                  123     6.2  393727              325.02       40.0  \n",
       "..                 ...     ...     ...                 ...        ...  \n",
       "995                111     6.2   27585              666.00       45.0  \n",
       "996                 94     5.5   73152               17.54       46.0  \n",
       "997                 98     6.2   70699               58.01       50.0  \n",
       "998                 93     5.6    4881              666.00       22.0  \n",
       "999                 87     5.3   12435               19.64       11.0  \n",
       "\n",
       "[1000 rows x 12 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_movie"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 特殊标记的处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1000025</th>\n",
       "      <th>5</th>\n",
       "      <th>1</th>\n",
       "      <th>1.1</th>\n",
       "      <th>1.2</th>\n",
       "      <th>2</th>\n",
       "      <th>1.3</th>\n",
       "      <th>3</th>\n",
       "      <th>1.4</th>\n",
       "      <th>1.5</th>\n",
       "      <th>2.1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1002945</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1015425</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1016277</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1017023</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1017122</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>693</th>\n",
       "      <td>776715</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>694</th>\n",
       "      <td>841769</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>695</th>\n",
       "      <td>888820</td>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696</th>\n",
       "      <td>897471</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>697</th>\n",
       "      <td>897471</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>698 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     1000025  5   1  1.1  1.2  2 1.3   3  1.4  1.5  2.1\n",
       "0    1002945  5   4    4    5  7  10   3    2    1    2\n",
       "1    1015425  3   1    1    1  2   2   3    1    1    2\n",
       "2    1016277  6   8    8    1  3   4   3    7    1    2\n",
       "3    1017023  4   1    1    3  2   1   3    1    1    2\n",
       "4    1017122  8  10   10    8  7  10   9    7    1    4\n",
       "..       ... ..  ..  ...  ... ..  ..  ..  ...  ...  ...\n",
       "693   776715  3   1    1    1  3   2   1    1    1    2\n",
       "694   841769  2   1    1    1  2   1   1    1    1    2\n",
       "695   888820  5  10   10    3  7   3   8   10    2    4\n",
       "696   897471  4   8    6    4  3   4  10    6    1    4\n",
       "697   897471  4   8    8    5  4   5  10    4    1    4\n",
       "\n",
       "[698 rows x 11 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe.replace(to_replace='要替换的值', value='替换后的值')\n",
    "wis = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data\")\n",
    "wis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_wis = wis.replace(to_replace=1, value='?')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_wis = new_wis.replace(to_replace='?', value=np.nan)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1000025</th>\n",
       "      <th>5</th>\n",
       "      <th>1</th>\n",
       "      <th>1.1</th>\n",
       "      <th>1.2</th>\n",
       "      <th>2</th>\n",
       "      <th>1.3</th>\n",
       "      <th>3</th>\n",
       "      <th>1.4</th>\n",
       "      <th>1.5</th>\n",
       "      <th>2.1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1002945</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>10</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1015425</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1016277</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4</td>\n",
       "      <td>3.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1017023</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1017122</td>\n",
       "      <td>8.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>10</td>\n",
       "      <td>9.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>693</th>\n",
       "      <td>776715</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>694</th>\n",
       "      <td>841769</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>695</th>\n",
       "      <td>888820</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3</td>\n",
       "      <td>8.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696</th>\n",
       "      <td>897471</td>\n",
       "      <td>4.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4</td>\n",
       "      <td>10.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>697</th>\n",
       "      <td>897471</td>\n",
       "      <td>4.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5</td>\n",
       "      <td>10.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>698 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     1000025    5     1   1.1  1.2    2 1.3     3   1.4  1.5  2.1\n",
       "0    1002945  5.0   4.0   4.0  5.0  7.0  10   3.0   2.0  1.0    2\n",
       "1    1015425  3.0   1.0   1.0  1.0  2.0   2   3.0   1.0  1.0    2\n",
       "2    1016277  6.0   8.0   8.0  1.0  3.0   4   3.0   7.0  1.0    2\n",
       "3    1017023  4.0   1.0   1.0  3.0  2.0   1   3.0   1.0  1.0    2\n",
       "4    1017122  8.0  10.0  10.0  8.0  7.0  10   9.0   7.0  1.0    4\n",
       "..       ...  ...   ...   ...  ...  ...  ..   ...   ...  ...  ...\n",
       "693   776715  3.0   1.0   1.0  1.0  3.0   2   1.0   1.0  1.0    2\n",
       "694   841769  2.0   1.0   1.0  1.0  2.0   1   1.0   1.0  1.0    2\n",
       "695   888820  5.0  10.0  10.0  3.0  7.0   3   8.0  10.0  2.0    4\n",
       "696   897471  4.0   8.0   6.0  4.0  3.0   4  10.0   6.0  1.0    4\n",
       "697   897471  4.0   8.0   8.0  5.0  4.0   5  10.0   4.0  1.0    4\n",
       "\n",
       "[698 rows x 11 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_wis.replace(to_replace=np.nan, value=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
